package com.tarena.luban.worker.server.controller;

import com.alibaba.fastjson.JSON;
import com.tarena.luban.worker.server.assemble.WorkerAssemble;
import com.tarena.luban.worker.server.domain.bo.WorkerBO;
import com.tarena.luban.worker.server.domain.service.WorkerService;
import com.tarena.luban.worker.server.vo.WorkerVO;
import com.tarena.passport.protocol.LoginUser;
import com.tarena.passport.sdk.context.SecurityContext;
import com.tarena.tp.luban.worker.server.dto.param.WorkerCreateParam;
import com.tedu.inn.protocol.exception.BusinessException;
import com.tedu.inn.protocol.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 手机app端接口 http入口类
 */
@RestController
public class WorkerController {
    @Autowired
    private WorkerService workerService;
    /**
     * 师傅注入  整体是数据的写操作
     * @RequestBody 接收请求体json字符串
     * 默认接收的表单格式数据 userId=1&realName=张三
     */
    @PostMapping("/worker/create")
    public Result<Long> createWorker(
            @RequestBody WorkerCreateParam workerCreateParam) throws BusinessException {
        Long workerId=workerService.create(workerCreateParam);
        return new Result<>(workerId);
    }
    /**
     * 手机app端师傅详情查询,每个用户登陆之后,访问工作台都会访问这个接口
     */
    @Autowired
    private WorkerAssemble workerAssemble;
    @GetMapping("/worker/detail")
    public Result<WorkerVO> detailWorker()throws BusinessException{
        //只要是查询,由于目前结构约定,一定业务层返回BO 在控制层要转化
        WorkerBO workerBO=workerService.detailWorker();
        //封装 转化方法无论如何都会返回一个workerVO 非空对象 其中属性 accountVO 在业务层封装accountBO不能是null
        WorkerVO workerVO = workerAssemble.assembleBO2VO(workerBO);
        return new Result<>(workerVO);
    }
}




















